package com.example.edu.web;

import com.example.edu.dao.AccountDao;
import com.example.edu.domain.Account;

import javax.servlet.http.HttpServletRequest;

/**
 * @author yanzhao
 * @date 2022/2/9 10:43
 * @since 1.0.0
 */
public class LoginController {

    private final AccountDao accountDao;

    public LoginController(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public Object login(HttpServletRequest request) {
        final String username = request.getParameter("username");
        final String password = request.getParameter("password");

        try {
            final Account account = accountDao.findAccount(username, password);
            if (account == null) {
                return "/login";
            } else {
                return "/index";
            }
        } catch (Exception e) {
            return "505";
        }
    }
}
